import axios from 'axios';

export interface ServerItem {
  id?: number | string;
  serverName: string;
  serverIp: string;
  serverPort: number;
  status: number;
  platformId?: number | string;
  createTime?: string;
  updateTime?: string;
  remark?: string;
}

export interface ServerPageData {
  records: ServerItem[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

export interface PlatformItem {
  id: number | string;
  platformName: string;
  [key: string]: any;
}

// 分页查询服务器列表
export function getServerPage(params: {
  current: number;
  size: number;
  serverName?: string;
  status?: number;
}) {
  return axios.get<ApiResponse<ServerPageData>>('/api/forward/server/page', {
    params,
  });
}

// 获取服务器详情
export function getServerDetail(id: number | string) {
  return axios.get<ApiResponse<ServerItem>>(`/api/forward/server/${id}`);
}

// 新增服务器
export function addServer(data: Omit<ServerItem, 'id' | 'createTime' | 'updateTime'>) {
  return axios.post<ApiResponse<ServerItem>>('/api/forward/server', data);
}

// 更新服务器
export function updateServer(data: ServerItem) {
  return axios.put<ApiResponse<boolean>>('/api/forward/server', data);
}

// 删除服务器
export function deleteServer(id: number | string) {
  return axios.delete<ApiResponse<boolean>>(`/api/forward/server/${id}`);
}

// 获取平台列表
export function getPlatformList() {
  return axios.get<ApiResponse<PlatformItem[]>>('/api/platform/list');
} 